// 最长连续序列

let nums = [100,4,200,1,3,2]

var longestConsecutive = function(nums) {
    if(nums.length === 0) return 0
    const set = new Set(nums)
    const n = nums.length
    let reslen = 1
    for(let i = 0; i < n; i++) {
        // 要么找最小的，要么找最大的
        if(!set.has(nums[i] - 1)) {
            let maxLen = 1
            let currentNum = nums[i]
            while(set.has(currentNum + 1)) {
                currentNum += 1
                maxLen++
            }
            reslen = Math.max(maxLen, reslen)
        }
    }
    return reslen
}